package com.google.appengine.echogear.core;

import java.util.Date;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query;

public final class Register {
	
	private static DatastoreService datastore;	
	
	static {
		datastore = DatastoreServiceFactory.getDatastoreService();
	}
	
	public static void add(String name, String clazz, String param, String user) {
		Entity service = new Entity("Service");
		service.setProperty("name", name);
		service.setProperty("class", clazz);
		service.setProperty("param", param);
		service.setProperty("user", user);
		service.setProperty("create", new Date());
		datastore.put(service);
	}
	
	public static Iterable<Entity> load() {
		Query query = new Query("Service");
		PreparedQuery preparedQuery = datastore.prepare(query);
		return preparedQuery.asIterable();
	}
}
